package com.rrd.dw.mr.gzip.kafka;

import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.icecredit.IceCreditRateStratificationRecord;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import java.io.IOException;

/**
 * 冰鉴利率分层模型
 *
 * @author guoqiang
 */

public class IceCreditRateStratificationParse extends ParseBase {
    private Text val = new Text();
    private Text key = new Text();

    /**
     * 冰鉴利率分层模型
     *
     * @param model
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    public boolean parseJob(Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        IceCreditRateStratificationRecord obj = (IceCreditRateStratificationRecord) model;
        StringBuilder sb = getBaseInfo(obj, successful);

        StringBuilder TxSb = new StringBuilder(500);
        TxSb.append(formatValue(obj.getResponseCode())).append(CRT001);
        TxSb.append(formatValue(obj.getMessage())).append(CRT001);
        TxSb.append(formatValue(obj.getTraceId())).append(CRT001);
        TxSb.append(formatValue(obj.getClass1Score())).append(CRT001);
        TxSb.append(formatValue(obj.getClass2Score())).append(CRT001);
        TxSb.append(formatValue(obj.getClass3Score())).append(CRT001);
        TxSb.append(formatValue(obj.getHitStatus())).append(CRT001);
        TxSb.append(formatValue(obj.getScene())).append(CRT001);
        key.set(getKey());
        val.set((sb.toString() + TxSb).replace("\n", " ").replace("\r", " "));
        context.write(key, val);
        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_ice_credit_rate_stratification_inc";
    }

    @Override
    public String getType() {
        return RecordType.ICE_CREDIT_RATE_STRATIFICATION_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "冰鉴利率分层模型";
    }
}
